(function () {
  var ie = !!(window.attachEvent && !window.opera);
  var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525);
  var fn = [];
  var run = function () { for (var i = 0; i < fn.length; i++) fn[i](); };
  var d = document;
  d.ready = function (f) {
    if (!ie && !wk && d.addEventListener)
      return d.addEventListener('DOMContentLoaded', f, false);
    if (fn.push(f) > 1) return;
    if (ie)
      (function () {
        try { d.documentElement.doScroll('left'); run(); }
        catch (err) { setTimeout(arguments.callee, 0); }
      })();
    else if (wk)
      var t = setInterval(function () {
        if (/^(loaded|complete)$/.test(d.readyState))
          clearInterval(t), run();
      }, 0);
  };
})();

function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}

function register(){
	if(!document.getElementById("username").value === "") {
		setCookie("accountName",document.getElementById("username").value,365);
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays===null) ? "" : "; expires="+exdate.toGMTString());
}

document.ready(function(){
	if (document.querySelector('meta[name="account"]').getAttribute('content') == "true") {
		if (getCookie("accountName") === "") {
			document.getElementById("account").innerHTML="<div class=\"mdui-card\"><div class=\"mdui-card-primary\"><div class=\"mdui-card-primary-title\">欢迎来到CNBlockly<\/div><div class=\"mdui-card-primary-subtitle\">快速注册，只需一步，即可保存作品<\/div><div class=\"mdui-textfield mdui-textfield-floating-label\"><label class=\"mdui-textfield-label\">User Name<\/label><input id=\"username\" class=\"mdui-textfield-input\" type=\"text\" required\/><div class=\"mdui-textfield-error\">用户名不能为空<\/div><\/div><div class=\"mdui-card-actions\"><button class=\"mdui-btn mdui-ripple\" onClick=\"register();history.go(0);\">确定<\/button><\/div><\/div>";
						var inst = new mdui.Tooltip('#account_icon', {
     content: '未登录'
});
		} else {
			document.getElementById("account").innerHTML="<div class=\"mdui-card\"><div class=\"mdui-card-primary\"><div class=\"mdui-card-primary-title\">欢迎回到CNBlockly<\/div><div class=\"mdui-card-primary-subtitle\">你的作品列表<\/div><\/div><div class=\"mdui-card-actions\"><a class=\"mdui-btn mdui-ripple\" href=\"index.html\">返回主页<\/button><\/div><\/div>";
			var inst = new mdui.Tooltip('#account_icon', {
     content: getCookie("accountName")
});
		}
	} else {
	    if (getCookie("accountName") == "") {
			var inst2 = new mdui.Tooltip('#account_icon', {
            content: '未登录'
            });
		} else {
			var inst2 = new mdui.Tooltip('#account_icon', {
            content: getCookie("accountName")
            });
		}
	}
	if (document.querySelector('meta[name="type"]').getAttribute('content') == "guides") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><\/a><a href=\"blockly\/demos\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">widgets<\/i><label>Blockly<\/label><\/a><a href=\"guides.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"about.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "index") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"index.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><\/a><a href=\"blockly\/demos\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">widgets<\/i><label>Blockly<\/label><\/a><a href=\"guides.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"about.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "about") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><a href=\"blockly\/demos\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">widgets<\/i><label>Blockly<\/label><\/a><a href=\"guides.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"about.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "guides2") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"..\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><a href=\"..\/blockly\/demos\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">widgets<\/i><label>Blockly<\/label><\/a><a href=\"..\/guides.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"..\/about.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "index2")	{
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"..\/index.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><a href=\"..\/guides.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"..\/about.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "about2") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"..\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><a href=\"..\/guides.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"..\/about.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else if (document.querySelector('meta[name="type"]').getAttribute('content') == "blockly") {
		document.getElementById("nav").innerHTML="<div class=\"mdui-bottom-nav mdui-color-indigo\"><a href=\"..\/..\/index.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">home<\/i><label>首页<\/label><\/a><a href=\"index.html\" class=\"mdui-ripple mdui-bottom-nav-active\"><i class=\"mdui-icon material-icons\">widgets<\/i><label>Blockly<\/label><\/a><a href=\"..\/..\/guides.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">library_books<\/i><label>教程<\/label><\/a><a href=\"..\/..\/about.html\" class=\"mdui-ripple\"><i class=\"mdui-icon material-icons\">info<\/i><label>关于<\/label><\/a><\/div>";
	} else {
		alert('底栏无法显示');
	}
});